﻿
//Global XMLHTTP Request object
var XmlHttp;

//Creating and setting the instance of appropriate XMLHTTP Request object to a “XmlHttp” variable  
function CreateXmlHttp()
{
	//Creating object of XMLHTTP in IE
	
	try
	{
		XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		
	}
	catch(e)
	{
	
		try
		{
			XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch(oc)
		{
			XmlHttp = null;
		}
	}
	
	//Creating object of XMLHTTP in Mozilla and Safari 
	if(!XmlHttp && typeof XMLHttpRequest != "undefined") 
	{
		XmlHttp = new XMLHttpRequest();
		
	}
	
}

//Gets called when country combo box selection changes
function ddlOnChange_ID(id) {    
	var ddlCategory = document.getElementById("DropModuleMenu");		
	var selectedCategory = ddlCategory.options[ddlCategory.selectedIndex].value;	
	var requestUrl ="AjaxServer.aspx?SelectedNode=" + encodeURIComponent(selectedCategory);	
	CreateXmlHttp();		
	if(XmlHttp)
	{	
		XmlHttp.onreadystatechange = HandleResponse;		
		//Initializes the request object with GET (METHOD of posting), 
		//Request URL and sets the request as asynchronous.
		XmlHttp.open("GET", requestUrl,  true);
		
		//Sends the request to server
		XmlHttp.send(null);				
	}
	
	// an hien cac check box	                 
    
    //if(moduType.value=='2')    
    //    ShowHide('inline','idRss');    
    // else
    //    ShowHide('none','idRss');
     if(moduType.value=='7')
        ShowHide('inline','idLinkUrl');    
     else
        ShowHide('none','idLinkUrl');               
        
    function ShowHide(value,idcheck){    
        var list = document.getElementsByName(idcheck);
        for (var i = 0; i < list.length; i++) {   
               list[i].style.display =value;
            } 
    }

    function selectOn(id)
    {                                       
    //    if(id==2)
    //        ShowHide('inline','idRss'); 
    //    else
    //        ShowHide('none','idRss');     
              
        if(id==7)        
            ShowHide('inline','idLinkUrl');
        else        
            ShowHide('none','idLinkUrl');                
    } 
}

function ShowHide(value,idcheck){    
    var list = document.getElementsByName(idcheck);
    for (var i = 0; i < list.length; i++) {   
           list[i].style.display =value;
        } 
}
//Called when response comes back from server
function HandleResponse()
{
    
	// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200)
		{	
			if(XmlHttp.responseXML != null)
			{
			    GetData(XmlHttp.responseXML);
			}   		
		}
		else
		{
			alert("There was a problem retrieving the data:\n" + xmlHttp.statusText);
		}
	}
}

function GetData(Xml)
{  
    var TrangHienThi = document.getElementById("dropTrangHienThi");
   	
   	for (var count = TrangHienThi.options.length-1; count >-1; count--)
	{
		TrangHienThi.options[count] = null;
	}
    
    var p = Xml.getElementsByTagName("zone");
    
    for(var i = 0; i < p.length; i++)
    {
        var value = p[i].firstChild.nodeValue;
        var id = p[i].attributes[0].value; 
        TrangHienThi.options[i] = new Option(value, id);
    }    
}